#include "MysqlSession.h"

#include <iostream>
#include <memory>

MysqlSession::MysqlSession(mysqlx::Session &&sess)
{
    session_ = std::make_unique<mysqlx::Session>(std::move(sess));
}

MysqlSession::~MysqlSession()
{
}

std::shared_ptr<mysqlx::Schema> MysqlSession::getSchema(const std::string &name)
{
    try {
        mysqlx::Schema schema = session_->getSchema(name);
        return std::make_shared<mysqlx::Schema>(schema);
    } catch (const std::exception &e) {
        std::cerr << "getSchema failed: " << e.what() << std::endl;
    }
    return std::shared_ptr<mysqlx::Schema>();
}

std::shared_ptr<mysqlx::Schema> MysqlSession::createSchema(const std::string &name)
{
    try {
        mysqlx::Schema schema = session_->createSchema(name);
        return std::make_shared<mysqlx::Schema>(schema);
    } catch (const std::exception &e) {
        std::cerr << "createSchema failed: " << e.what() << std::endl;
    }
    return std::shared_ptr<mysqlx::Schema>();
}